package com.squapsource.project_euler;

public class Problem17 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Integer maxNum = 1000;
		String numString = "";
		for (int i = 1; i <= maxNum; i++)
			numString += getWordFromNum(i);

		System.out.println(numString.length());

	}

	private static String getWordFromNum(Integer maxNum) {
		String numString = "";

		if (maxNum.toString().length() == 4) {
			numString += getWordFromNum(maxNum.toString().charAt(0))
					+ "thousand";
			maxNum -= Integer.parseInt(maxNum.toString().charAt(0) + "000");
		}
		if (maxNum.toString().length() == 3) {
			numString += getWordFromNum(maxNum.toString().charAt(0))
					+ "hundred";
			maxNum -= Integer.parseInt(maxNum.toString().charAt(0) + "00");
			if (maxNum > 0)
				numString += "and";
		}
		if (maxNum.toString().length() == 2) {

			if (maxNum.toString().charAt(0) == '1') {
				numString += getWordFromNumTeens(maxNum);
				maxNum = 0;
			}
			numString += getWordFromNumTens(maxNum.toString().charAt(0));
			maxNum -= Integer.parseInt(maxNum.toString().charAt(0) + "0");
		}
		if (maxNum.toString().length() == 1 && maxNum > 0) {
			numString += getWordFromNum(maxNum.toString().charAt(0));
		}
		return numString;
	}

	private static String getWordFromNumTeens(Integer maxNum) {
		switch (maxNum) {
		case 10:
			return "ten";
		case 11:
			return "eleven";
		case 12:
			return "twelve";
		case 13:
			return "thirteen";
		case 14:
			return "fourteen";
		case 15:
			return "fifteen";
		case 16:
			return "sixteem";
		case 17:
			return "seventeen";
		case 18:
			return "eighteen";
		case 19:
			return "nineteen";
		}
		return null;
	}

	private static String getWordFromNumTens(char charAt) {
		switch (charAt) {
		case '0':
			return "";
		case '1':
			return "one";
		case '2':
			return "twenty";
		case '3':
			return "thirty";
		case '4':
			return "forty";
		case '5':
			return "fifty";
		case '6':
			return "sixty";
		case '7':
			return "seventy";
		case '8':
			return "eighty";
		case '9':
			return "ninety";
		}
		return null;
	}

	private static String getWordFromNum(char charAt) {
		switch (charAt) {
		case '0':
			return "zero";
		case '1':
			return "one";
		case '2':
			return "two";
		case '3':
			return "three";
		case '4':
			return "four";
		case '5':
			return "five";
		case '6':
			return "six";
		case '7':
			return "seven";
		case '8':
			return "eight";
		case '9':
			return "nine";
		}
		return null;
	}

}
